#include "RingQueue.hpp"
#include "Sem.hpp"
#include <unistd.h>

void *producer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    int data = 1;
    while (1)
    {
        sleep(1);
        std::cout << "生产了一个数据" << data << std::endl;
        rq->Equeue(data);
        data++;
    }
}

void *consumer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    while (1)
    {
        sleep(2);
        int t = 0;
        rq->Pop(&t);
        std::cout << "消费者拿到了一个数据" << t << std::endl;
    }
}

int main()
{
    RingQueue<int> *rq = new RingQueue<int>(gcap);

    pthread_t c, p;

    pthread_create(&p, NULL, producer, rq);
    pthread_create(&c, NULL, consumer, rq);

    pthread_join(c, NULL);
    pthread_join(p, NULL);

    delete rq;

    return 0;
}